{extend name="public/layout" /}

{block name="content"}
<form class="layui-form" method="post">
    <div class="layui-form-item">
        <label for="old_password" class="layui-form-label"><span class="x-red">*</span>登录名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="old_password" class="layui-form-label"><span class="x-red">*</span>用户组</label>
        <div class="layui-input-inline">
            <select name="role_id" lay-verify="required">
                {volist name="roles" id="vo"}
                    <option value="{$vo['id']}">{$vo['title']}</option>
                {/volist}
              </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label for="old_password" class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="old_password" class="layui-form-label">>邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="old_password" class="layui-form-label"><span class="x-red">*</span>是否启用</label>
        <div class="layui-input-inline">
            <input type="radio" name="enable" value="1" required  lay-verify="required" title="启用" checked>
            <input type="radio" name="enable" value="0" required  lay-verify="required" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="old_password" class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="name"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" id="last">
        <label for="L_repass" class="layui-form-label"></label>
        <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
    </div>  
</form>
{/block}

{block name="header"}
<style>
    body{
        background: #fff;
    }
</style>
{/block}

{block name="foot"}
<script>
    layui.use(['form','layer'], function(){
        console.log($)
        var form = layui.form
        form.on('submit(add)',function(data){
            var field = {
                'old_password':data.field.old_password,
                'new_password':data.field.new_password,
            }
            var index = layer.load();   
            $.ajax({
                url:data.form.action,
                data:data.field,
                type:data.form.method,
                success:function(data){
                    layer.close(index);
                    layer.alert(data.msg,{icon:data.err_code === 200?6:5,end:function(){
                        if(data.err_code === 200){
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.location.reload();
                        }
                    }});
                },
                error:function(){
                    layer.close(index);
                    layer.alert("服务器出现错误")
                }
            })
            return false;
        });
    });

</script>
{/block}